<template>
  <div>
    <div class="btn-box">
      <el-button type="info" @click="getLocationInfo">定位锚点</el-button>
      <el-button type="info" @click="myFly">飞向锚点</el-button>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { ElMessage } from 'element-plus' // 添加 ElMessage 引入
const props = defineProps({
  objm: {
    type: Object,
    required: true,
  },
})
const location = ref(null)
const camera = ref(null)
// 获取当前视角信息
const getLocationInfo = () => {
  const view = props.objm.activeViewer.getCurrentCameraInfo()
  console.log('当前视角信息', view)
  if (!view) {
    ElMessage({
      message: '当前视角信息为空',
      type: 'warrning',
      showClose: true, //信息关闭按钮
      grouping: true, //相同信息合并
      duration: 1000, //显示时间
    })
    return
  }
  const { position, rotation } = view
  location.value = position
  camera.value = rotation
}
const myFly = () => {
  props.objm.activeViewer.flyIn(location.value, camera.value, 3)
}
</script>

<style lang="scss" scoped>
.btn-box {
  button {
    height: 40px;
  }
}
</style>
